package cn.stylefeng.guns.modular.thread.pool;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author liuyao
 * 线程池
 */
@EnableAsync
@Slf4j
@Component
@Configuration
public class ExecutorConfig {



    /**
     * @return
     */
    @Bean("sendToAlias")
    public ThreadPoolTaskExecutor sendToAlias() {
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new VisiableThreadPoolTaskExecutor();
        //核心线程数
        threadPoolTaskExecutor.setCorePoolSize(10);
        threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true);
        //最大线程数
        threadPoolTaskExecutor.setMaxPoolSize(2000);
        //配置队列大小
        threadPoolTaskExecutor.setQueueCapacity(5000);
        //配置线程池前缀
        threadPoolTaskExecutor.setThreadNamePrefix("addSearchRecord-service-");
        //拒绝策略
        threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        threadPoolTaskExecutor.initialize();
        return threadPoolTaskExecutor;
    }


    /**
     * 删除用户浏览记录
     * @return
     */
    @Bean("deleteUserBrowse")
    public ThreadPoolTaskExecutor deleteUserBrowse() {
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new VisiableThreadPoolTaskExecutor();
        //核心线程数
        threadPoolTaskExecutor.setCorePoolSize(10);
        threadPoolTaskExecutor.setAllowCoreThreadTimeOut(true);
        //最大线程数
        threadPoolTaskExecutor.setMaxPoolSize(2000);
        //配置队列大小
        threadPoolTaskExecutor.setQueueCapacity(5000);
        //配置线程池前缀
        threadPoolTaskExecutor.setThreadNamePrefix("addSearchRecord-service-");
        //拒绝策略
        threadPoolTaskExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
        threadPoolTaskExecutor.initialize();
        return threadPoolTaskExecutor;
    }



}